home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / FWPolySh.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  9.6 KB  |  332 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPolySh.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWPOLYSH_H
  13. #include "FWPolySh.h"
  14. #endif
  15.  
  16. #ifndef SLGRGLOB_H
  17. #include "SLGrGlob.h"
  18. #endif
  19.  
  20. #ifndef FWGRUTIL_H
  21. #include "FWGrUtil.h"
  22. #endif
  23.  
  24. #ifndef FWGC_H
  25. #include "FWGC.h"
  26. #endif
  27.  
  28. #ifndef FWINK_H
  29. #include "FWInk.h"
  30. #endif
  31.  
  32. #ifndef FWSTYLE_H
  33. #include "FWStyle.h"
  34. #endif
  35.  
  36. #ifndef SLRENDER_H
  37. #include "SLRender.h"
  38. #endif
  39.  
  40. #ifndef FWPOLY_H
  41. #include "FWPoly.h"
  42. #endif
  43.  
  44. // ----- Foundation Includes -----
  45.  
  46. #ifndef FWSTREAM_H
  47. #include "FWStream.h"
  48. #endif
  49.  
  50. // ----- OpenDoc Includes -----
  51.  
  52. #ifndef _TRANSFORM_
  53. #include <Trnsform.xh>
  54. #endif
  55.  
  56. //========================================================================================
  57. // File scope definitions
  58. //========================================================================================
  59.  
  60. #ifdef FW_BUILD_MAC
  61. #pragma segment FWGraphx_PolygonShape
  62. #endif
  63.  
  64. //========================================================================================
  65. //    class FW_CPolygonShape
  66. //========================================================================================
  67.  
  68. FW_DEFINE_AUTO(FW_CPolygonShape)
  69. FW_DEFINE_CLASS_M1(FW_CPolygonShape, FW_CShape)
  70.  
  71. // This class is archivable, but we provide the archiving implementation in a separate
  72. // translation unit in order to enable deadstripping of the archiving-related code
  73. // in parts that do not use archiving with this class.
  74.  
  75. //----------------------------------------------------------------------------------------
  76. //    FW_CPolygonShape::FW_CPolygonShape
  77. //----------------------------------------------------------------------------------------
  78.  
  79. FW_CPolygonShape::FW_CPolygonShape(const FW_CPolygon& polygon,
  80.                                     FW_ERenderVerbs renderVerb,
  81.                                    FW_Boolean autoCloseFrame,
  82.                                    const FW_CInk& ink,
  83.                                    const FW_CStyle& style) :
  84.     FW_CShape(renderVerb, ink, style, FW_kNormalFont),
  85.     fPolygon(polygon),
  86.     fAutoCloseFrame(autoCloseFrame)
  87. {
  88.     FW_END_CONSTRUCTOR
  89. }
  90.  
  91. //----------------------------------------------------------------------------------------
  92. //    FW_CPolygonShape::FW_CPolygonShape
  93. //----------------------------------------------------------------------------------------
  94.  
  95. FW_CPolygonShape::FW_CPolygonShape(const FW_CPolygonShape& other) :
  96.     FW_CShape(other),
  97.     fPolygon(other.fPolygon),
  98.     fAutoCloseFrame(other.fAutoCloseFrame)
  99. {
  100.     FW_END_CONSTRUCTOR
  101. }
  102.  
  103. //----------------------------------------------------------------------------------------
  104. //    FW_CPolygonShape::FW_CPolygonShape
  105. //----------------------------------------------------------------------------------------
  106.  
  107. FW_CPolygonShape::FW_CPolygonShape(FW_CReadableStream& stream) :
  108.     FW_CShape(stream)
  109. {
  110.     stream >> fPolygon;
  111.  
  112.     FW_END_CONSTRUCTOR
  113. }
  114.  
  115. //----------------------------------------------------------------------------------------
  116. //    FW_CPolygonShape::~FW_CPolygonShape
  117. //----------------------------------------------------------------------------------------
  118.  
  119. FW_CPolygonShape::~FW_CPolygonShape()
  120. {
  121.     FW_START_DESTRUCTOR
  122. }
  123.  
  124. //----------------------------------------------------------------------------------------
  125. //    FW_CPolygonShape::operator=
  126. //----------------------------------------------------------------------------------------
  127.  
  128. FW_CPolygonShape& FW_CPolygonShape::operator=(const FW_CPolygonShape& other)
  129. {
  130.     fPolygon = other.fPolygon;
  131.     return *this;
  132. }
  133.  
  134. //----------------------------------------------------------------------------------------
  135. //    FW_CPolygonShape::SetAutoCloseFrame
  136. //----------------------------------------------------------------------------------------
  137.  
  138. void FW_CPolygonShape::SetAutoCloseFrame(FW_Boolean autoCloseFrame)
  139. {
  140.     fAutoCloseFrame = autoCloseFrame;
  141. }
  142.  
  143. //----------------------------------------------------------------------------------------
  144. //    FW_CPolygonShape::GetAutoCloseFrame
  145. //----------------------------------------------------------------------------------------
  146.  
  147. FW_Boolean FW_CPolygonShape::GetAutoCloseFrame() const
  148. {
  149.     return fAutoCloseFrame;
  150. }
  151.  
  152. //----------------------------------------------------------------------------------------
  153. //    FW_CPolygonShape::Render
  154. //----------------------------------------------------------------------------------------
  155.  
  156. void FW_CPolygonShape::Render(FW_CGraphicContext& gc) const
  157. {
  158.     FW_PrivRenderPolygon(gc.GetEnvironment(),
  159.         gc,
  160.         fPolygon,
  161.         GetRenderVerb(),
  162.         fAutoCloseFrame,
  163.         fInk,
  164.         fStyle);
  165.     FW_FailOnEvError(gc.GetEnvironment());
  166. }
  167.  
  168. //----------------------------------------------------------------------------------------
  169. //    FW_CPolygonShape::HitTest
  170. //----------------------------------------------------------------------------------------
  171.  
  172. FW_Boolean FW_CPolygonShape::HitTest(FW_CGraphicContext& gc,
  173.                                      const FW_CPoint& test,
  174.                                      FW_Fixed tolerance) const
  175. {
  176. FW_UNUSED(gc);
  177.  
  178.     if(fRenderVerb == FW_kNoRendering)
  179.         return FALSE;
  180.         
  181.     // Quickly check the bounds
  182.     FW_CRect bounds;
  183.     fPolygon.GetBounds(bounds);
  184.  
  185.     bounds.Inset(-tolerance, -tolerance);
  186.  
  187.     if(bounds.Contains(test))
  188.     {
  189.         // Bounds check out OK, now do a more thourough test
  190.         long pointCount = fPolygon.GetCount();
  191.         const FW_SPoint* points = fPolygon.GetPoints();
  192.         if(fRenderVerb == FW_kFrame)
  193.         {
  194.             for(long i = 0; i < pointCount - 1; i ++)
  195.                 if(::FW_HitTestLine(points[i], points[i + 1], test, tolerance))
  196.                     return TRUE;
  197.         }
  198.         else
  199.             return ::FW_HitTestPolygon(pointCount, points, test);
  200.     }
  201.  
  202.     return FALSE;
  203. }
  204.  
  205. //----------------------------------------------------------------------------------------
  206. //    FW_CPolygonShape::Copy
  207. //----------------------------------------------------------------------------------------
  208.  
  209. FW_CShape* FW_CPolygonShape::Copy() const
  210. {
  211.     return FW_NEW(FW_CPolygonShape, (*this));
  212. }
  213.  
  214. //----------------------------------------------------------------------------------------
  215. //    FW_CPolygonShape::Transform
  216. //----------------------------------------------------------------------------------------
  217.  
  218. void FW_CPolygonShape::Transform(Environment *ev, ODTransform* transform)
  219. {
  220.     fPolygon.Transform(ev, transform);
  221. }
  222.  
  223. //----------------------------------------------------------------------------------------
  224. //    FW_CPolygonShape::InverseTransform
  225. //----------------------------------------------------------------------------------------
  226.  
  227. void FW_CPolygonShape::InverseTransform(Environment *ev, ODTransform* transform)
  228. {
  229.     fPolygon.InverseTransform(ev, transform);
  230. }
  231.  
  232. //----------------------------------------------------------------------------------------
  233. //    FW_CPolygonShape::MoveShape
  234. //----------------------------------------------------------------------------------------
  235.  
  236. void FW_CPolygonShape::MoveShape(FW_Fixed deltaX, FW_Fixed deltaY)
  237. {
  238.     fPolygon.Move(deltaX, deltaY);
  239. }
  240.  
  241. //----------------------------------------------------------------------------------------
  242. //    FW_CPolygonShape::MoveShapeTo
  243. //----------------------------------------------------------------------------------------
  244.  
  245. void FW_CPolygonShape::MoveShapeTo(FW_Fixed x, FW_Fixed y)
  246. {
  247.     fPolygon.MoveTo(x, y);
  248. }
  249.  
  250. //----------------------------------------------------------------------------------------
  251. //    FW_CPolygonShape::Inset
  252. //----------------------------------------------------------------------------------------
  253.  
  254. void FW_CPolygonShape::Inset(FW_Fixed x, FW_Fixed y)
  255. {
  256.     fPolygon.Inset(x, y);
  257. }
  258.  
  259. //----------------------------------------------------------------------------------------
  260. //    FW_CPolygonShape::GetBounds
  261. //----------------------------------------------------------------------------------------
  262.  
  263. void FW_CPolygonShape::GetBounds(FW_CGraphicContext& gc, FW_CRect& rect) const
  264. {
  265. FW_UNUSED(gc);
  266.  
  267.     fPolygon.GetBounds(rect);
  268. }
  269.  
  270. //----------------------------------------------------------------------------------------
  271. //    FW_CPolygonShape::GetAnchorPoint
  272. //----------------------------------------------------------------------------------------
  273.  
  274. FW_CPoint FW_CPolygonShape::GetAnchorPoint() const
  275. {
  276.     FW_CRect rect;
  277.     fPolygon.GetBounds(rect);
  278.     
  279.     return rect.TopLeft();
  280. }
  281.  
  282. //----------------------------------------------------------------------------------------
  283. //    FW_CPolygonShape::Flatten
  284. //----------------------------------------------------------------------------------------
  285.  
  286. void FW_CPolygonShape::Flatten(FW_CWritableStream& stream) const
  287. {
  288.     FW_CShape::Flatten(stream);
  289.     
  290.     stream << fPolygon;
  291. }
  292.  
  293. //----------------------------------------------------------------------------------------
  294. //    FW_CPolygonShape::RenderPolygon
  295. //----------------------------------------------------------------------------------------
  296.  
  297. void FW_CPolygonShape::RenderPolygon(FW_CGraphicContext& gc,
  298.                                          const FW_CPolygon& polygon,
  299.                                          FW_ERenderVerbs renderVerb,
  300.                                      FW_Boolean autoCloseFrame,
  301.                                      const FW_CInk& ink,
  302.                                          const FW_CStyle& style)
  303. {
  304.     FW_PrivRenderPolygon(gc.GetEnvironment(),
  305.         gc,
  306.         polygon,
  307.         renderVerb,
  308.         autoCloseFrame,
  309.         ink,
  310.         style);
  311.     FW_FailOnEvError(gc.GetEnvironment());
  312. }
  313.  
  314. //----------------------------------------------------------------------------------------
  315. //    FW_CPolygonShape::GetGeometry
  316. //----------------------------------------------------------------------------------------
  317.  
  318. void FW_CPolygonShape::GetGeometry(FW_CPolygon& polygon) const
  319. {
  320.     polygon = fPolygon;
  321. }
  322.  
  323. //----------------------------------------------------------------------------------------
  324. //    FW_CPolygonShape::SetGeometry
  325. //----------------------------------------------------------------------------------------
  326.  
  327. void FW_CPolygonShape::SetGeometry(const FW_CPolygon& polygon)
  328. {
  329.     fPolygon = polygon;
  330. }
  331.  
  332.